import { postAuthentication,getIdentity} from './services';

export default {
  namespace: 'authentication',
  effects: {
    *sendAuthentication({ payload }, { call, put }) {
      const response = yield call(postAuthentication, payload);
      const { code, msg } = response;
      if (code === 1) {
        return Promise.resolve(msg);
      }
      return Promise.reject(msg);
    },
    *getIdentity({ payload }, { call, put }) {
      const response = yield call(getIdentity);
      const { code, data } = response;
      if (code === 1) {
        yield put({
          type: 'updateUserInformation',
          payload: data,
        });
      }
    },
  },
  reducers: {
    updateUserInformation(state, { payload }) {
      state.information = payload;
      return state;
    },
  },
};
